package peer.p2pnet.message;

import java.net.DatagramPacket;

import peer.Config;
import peer.Message;
import peer.tools.ByteIntSwitch;
import peer.tools.ByteShortSwitch;

public class CastGroupRandomMessage extends Message{
	public short sType=peer.tools.MessageType.sType_CastGroupRandomMessage;
	int sessionId =0;
	byte[] dpData=null;
	byte[] md=null;
	public CastGroupRandomMessage(byte[] md){
		this.md=md;
		dpData=new byte[24];
		ByteShortSwitch.toByteArray(ver, dpData, 0);  //add: ver
		ByteShortSwitch.toByteArray(sType, dpData, 2);  //add: service type
		ByteIntSwitch.toByteArray(Config.sessionId, dpData, 4);  //add: sessionId
		System.arraycopy(md, 0, dpData, 8, 16);
		
		dp=new DatagramPacket(dpData,dpData.length);
	}
	
	public CastGroupRandomMessage(DatagramPacket dp){
		this.dp=dp;
		dpData=dp.getData();
		ver=ByteShortSwitch.toShort(dpData, 0);
		sType=ByteShortSwitch.toShort(dpData, 2);
		sessionId=ByteIntSwitch.toInt(dpData, 4);
		md=new byte[16];
		System.arraycopy(dpData, 8, md, 0, 16);
	}
	
	public int getSessionId (){
		return sessionId ;
	}
	
	public byte[] getMd(){
		return md;
	}


}
